package com.itheima.d4_synchronized_code;

public class Ticket implements Runnable {
    private int ticket = 100;
    private int sum = 0;

    @Override
    public void run() {
        while (true) {
            synchronized (Ticket.class) {
                if (ticket <= 0) {
                    break;
                } else {

                    ticket--;
                    System.out.println(Thread.currentThread().getName() + "在卖票，还剩 " + ticket + " 张" + "  总卖：" + ++sum);
                }
            }
            try {
                Thread.sleep(30);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }


        }


    }

}
